/**
 * 文件名：ArticleService
 * 版权：Copyright by www.fsmeeting.com
 * 描述：
 * 修改人：kezs
 * 修改时间：2017/10/11
 * 修改内容：
 */
package com.huluhome.service.impl;

import com.huluhome.constant.DictEnum;
import com.huluhome.dao.IArticleDao;
import com.huluhome.domain.AddArticleBo;
import com.huluhome.domain.Article;
import com.huluhome.domain.ArticleQueryModel;
import com.huluhome.domain.ArticleReply;
import com.huluhome.domain.HotWord;
import com.huluhome.service.IArticleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 〈一句话功能简述〉
 *
 * @author kezs
 * @version 2017/10/11
 * @see ArticleService
 */
@Service("articleService")
public class ArticleService implements IArticleService {

    @Resource
    private IArticleDao articleDao;

    @Override
    public List<Article> getArticles(ArticleQueryModel articleQueryModel) {
        return articleDao.getArticles(articleQueryModel);
    }

    @Override
    public Article getArticle(ArticleQueryModel articleQueryModel) {
        List<Article> articles = articleDao.getArticles(articleQueryModel);
        if ( articles != null && articles.size() > 0) {
            return articles.get(0);
        }
        return null;
    }

    @Override
    public int addArticle(AddArticleBo articleBo) {
        Article article = new Article();
        article.setTitle(articleBo.getTitle());
        article.setContent(articleBo.getContent());
        article.setAuthor(articleBo.getAuthor());
        article.setRemark(articleBo.getRemark());
        article.setCreateTime(new Date());
        article.setKeyword(articleBo.getKeyword());
        article.setClickCount(articleBo.getClickCount());
        article.setRealClickCount(0);
        article.setReplyCount(0);
        article.setCategoryId(articleBo.getCategoryId());
        article.setCategoryName(articleBo.getCategoryName());
        article.setStatus(articleBo.getStatus());
        article.setPicUrl(articleBo.getPicUrl());
        article.setRecommId(articleBo.getRecommId());
        return articleDao.addArticle(article);
    }

    @Override
    public List<ArticleReply> getArticleReplies(ArticleReply articleReply) {
        if (articleReply == null) {
            ArticleReply articleReply1 = new ArticleReply();
            articleReply1.setStatus(DictEnum.STATUS_ENBALE.getIntCodeValue());
            return articleDao.getArticleReplies(articleReply1);
        }
        return articleDao.getArticleReplies(articleReply);
    }

    @Override
    public int addArticleReply(ArticleReply articleReply) {
        return articleDao.addArticleReply(articleReply);
    }

    @Override
    public List<HotWord> getHotWords() {
        return articleDao.getHotWords();
    }

    @Override
    public int addHotWord(String keyword, int articleId) {
        HotWord hotWord = new HotWord();
        hotWord.setKeyword(keyword);
        hotWord.setArticleId(articleId);
        return articleDao.addHotWord(hotWord);
    }

    @Override
    public int deleteArticle(int articleId) {
        return articleDao.deleteArticle(articleId);
    }
}
